﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DrSoftsFrame.Servers;
using System.Data;
using System.Data.SqlClient;
using PreeRegisterModel;

namespace PreeRegisterDAL
{
    public class CheckReportDAL
    {

        /// <summary>
        /// 查询体检报告列表
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
        public static DataSet Getcheckreport(CheckReportListRequestModel request)
        {
            try
            {
                CheckDb mydb = new CheckDb();
                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "up_getchecgroup";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p1 = new SqlParameter("@checkcode", SqlDbType.VarChar, 20);
                p1.Direction = ParameterDirection.Input;
                p1.Value = request.checkcode;
                cmd.Parameters.Add(p1);

                SqlParameter p2 = new SqlParameter("@idcard_inout", SqlDbType.VarChar, 20);
                p2.Direction = ParameterDirection.Input;
                p2.Value = request.idcard;
                cmd.Parameters.Add(p2);

                DataSet ds = mydb.ExecuteSqlCmdFillDs(cmd);

                if (ds == null )
                {
                    return null;
                }
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }


        /// <summary>
        /// 查询体检报告明细
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
        public static DataSet GetCheckReportList(string ienrolapplyno)
        {
            try
            {
                CheckDb mydb = new CheckDb();

                string sql = string.Format(@" SELECT iEnrolApplyNo,iCheckGroupNo,cGroupName FROM dbo.infoEnrolApply WHERE iEnrolApplyNo={0} ;
SELECT cCheckItemName,iCheckItemNo,b.iCheckGroupNo,cResult,cBount,cUnit,cResultFlag 
FROM dbo.infoEnrolApplyDetail a 
JOIN dbo.infoEnrolApply b ON a.iEnrolApplyNo=b.iEnrolApplyNo
 WHERE a.iEnrolApplyNo={0}", ienrolapplyno);
                DataSet ds = mydb.ExecuteSelect(sql);

                if (ds == null || ds.Tables[0].Rows.Count <1)
                {
                    return null;
                }
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }

        /// <summary>
        /// 查询体检综检建议
        /// </summary>
        /// <param name="cpatientcode"></param>
        /// <returns></returns>
        public static DataSet Getcheckadvices(CheckAdvicesListRequestModel request)
        {
            try
            {
                CheckDb mydb = new CheckDb();
                SqlCommand cmd = new SqlCommand();

                cmd.CommandText = "up_getAdvice ";
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter p1 = new SqlParameter("@checkcode", SqlDbType.VarChar, 20);
                p1.Direction = ParameterDirection.Input;
                p1.Value = request.checkcode;
                cmd.Parameters.Add(p1);

                SqlParameter p2 = new SqlParameter("@idcard_inout", SqlDbType.VarChar, 20);
                p2.Direction = ParameterDirection.Input;
                p2.Value = request.idcard;
                cmd.Parameters.Add(p2);

                DataSet ds = mydb.ExecuteSqlCmdFillDs(cmd);

                if (ds == null || ds.Tables.Count < 1)
                {
                    return null;
                }
                return ds;

            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
